import * as func from "./func.js"
export default {
  name: '',
  components:{},
  data(){
    return {
      list: [],
      curIndex: 0,
      timer: null
    }
  },
  methods:{
    ...func,
  },
  created(){
    this.list =  [
      { id: _.guID(), name: '张三', age: 18, interst: '篮球'},
      { id: _.guID(), name: '李四', age: 20, interst: '羽毛球'},
      { id: _.guID(), name: '王五', age: 15, interst: '乒乓球'},
      { id: _.guID(), name: '朱晓明', age: 25, interst: '足球'},
      { id: _.guID(), name: '王一多', age: 27, interst: '篮球'},
      { id: _.guID(), name: '许三强', age: 12, interst: '围棋'},
      { id: _.guID(), name: '陈胜', age: 22, interst: '象棋'},
      { id: _.guID(), name: '刘邦', age: 45, interst: '军旗'},
      { id: _.guID(), name: '项羽', age: 32, interst: '军事'},
      { id: _.guID(), name: '陈平', age: 32, interst: '谋略'},
    ]
    this.showList = [...this.list, ...this.list.slice(0, 5).map(v => ({...v, id: _.guID()}))] // 用于展示的轮播图需要底部进行拼接
    this.timer = setInterval(() => {
      // 当加载到最后一项的时候，关闭动画。将curIndex归位
      if(this.curIndex == this.list.length) {
        this.curIndex = 0
        return setTimeout(() => {this.curIndex++}, 20)
      }
      this.curIndex++
    },1500)
  },
  mounted(){
    
  },
  beforeDestroy() {
    clearInterval(this.timer) // 清楚定时器，否则就会造成内存泄露
  },
}